home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-23 | 4.1 KB | 173 lines | [TEXT/PJMM] |
- unit MyNotifier;
- { DeHQX v2.0.0 © Peter Lewis, Aug 1991 }
-
- { Derived from <jholt@adobe.COM> Joe Holt's StartupError code as posted }
- { to comp.sys.mac.programmer May 1991 }
-
- { Notification Manager messages }
-
- { History: }
- { jhh 18 jun 90 -- response to news posting }
- { pnl 29 may 91 -- Converted to pascal to be used in an application }
-
- interface
-
- uses
- Notification;
-
- procedure InitNotify;
- procedure FinishNotify;
- procedure Notify (mark, sound: boolean; sicn_id, sicn_index, str_id, str_index: integer);
- { mark - mark the current application }
- { sound - play sysbeep }
- { sicn_id, sicn_index - SICN id to rotate with the apple & index (<1 -> 1) OR 0&0 for no sicn }
- { str_id, str_index - STR# id & index OR STR id & 0 OR 0 & 0 }
- procedure NotifyCompletion;
- { Call this when in event loop when in the foreground to remove apple mark and flash }
-
- implementation
-
- const
- sicn_size = 32;
- T_NMInstall = $A05E;
- T_Unimplemented = $A89F;
-
- type
- NMRecPtrPtr = ^NMRecPtr;
- booleanPtr = ^boolean;
-
- var
- current_note: NMRecPtr;
- notify_finished: boolean;
-
- { handles must be non-purgeable, but may be unlocked }
-
- procedure InitNotify;
- begin
- current_note := nil;
- notify_finished := false;
- end;
-
- procedure MyResponse (note: NMRecPtr);
- begin
- booleanPtr(note^.nmRefCon)^ := true;
- end;
-
- procedure UnNotify;
- var
- oe: OSErr;
- begin
- if current_note <> nil then begin
- oe := NMRemove(current_note);
- with current_note^ do begin
- if nmStr <> nil then
- DisposPtr(pointer(nmStr));
- if nmIcon <> nil then
- DisposHandle(nmIcon);
- end;
- DisposPtr(pointer(current_note));
- current_note := nil;
- end;
- notify_finished := false;
- end;
-
- procedure NotifyCompletion;
- begin
- if notify_finished then
- UnNotify;
- end;
-
- procedure FinishNotify;
- begin
- if current_note <> nil then
- UnNotify;
- end;
-
- procedure Notify (mark, sound: boolean; sicn_id, sicn_index, str_id, str_index: integer);
- var
- errorText: str255;
- sh: stringHandle;
- sicnH: handle;
- error: boolean;
- oe: OSErr;
- begin
- UnNotify; { Clear outstanding notify }
- if NGetTrapAddress(T_NMInstall, OSTrap) = NGetTrapAddress(T_Unimplemented, ToolTrap) then begin
- SysBeep(1); { Best we can do I guess. Could put up the dialog box maybe?...}
- end
- else begin
- current_note := NMRecPtr(NewPtr(sizeof(NMRec)));
- if current_note = nil then begin
- SysBeep(1); { Can't do much else if there isnt even room for this! }
- end
- else begin
- with current_note^ do begin
- qType := nmType;
- error := false;
- booleanPtr(nmRefCon) := @notify_finished;
- if mark then
- nmMark := 1
- else
- nmMark := 0;
- nmStr := nil;
- if str_id <> 0 then begin
- if str_index > 0 then
- GetIndString(errorText, str_id, str_index)
- else begin
- errorText := '';
- sh := GetString(str_id);
- if sh <> nil then begin
- if sh^ <> nil then
- errorText := sh^^;
- ReleaseResource(handle(sh));
- end;
- end;
- if errorText = '' then
- error := true
- else begin
- nmStr := stringPtr(NewPtr(length(errorText) + 1));
- if nmStr = nil then
- error := true
- else
- nmStr^ := errorText;
- end;
- end;
- nmIcon := nil;
- if sicn_id <> 0 then begin
- if sicn_index < 1 then
- sicn_index := 1;
- sicn_index := (sicn_index - 1) * sicn_size; { 1-based, like STR# }
- sicnH := GetResource('SICN', sicn_id);
- HNoPurge(sicnH);
- if sicnH = nil then
- error := true
- else begin
- nmIcon := NewHandle(sicn_size);
- if nmIcon = nil then
- error := true
- else if nmIcon^ = nil then
- error := true
- else if GetHandleSize(sicnH) < sicn_index + sicn_size then
- error := true
- else begin
- BlockMove(ptr(longInt(sicnH^) + sicn_index), nmIcon^, sicn_size);
- end;
- ReleaseResource(sicnH);
- end;
- end;
- if sound or error then
- nmSound := handle(-1)
- else
- nmSound := nil;
- nmResp := @MyResponse;
- end;
- oe := NMInstall(current_note);
- if oe <> noErr then begin
- current_note := nil;
- SysBeep(1);
- end;
- end;
- end;
- end;
-
- end.